package com.geek.gkbgw.framework.dispatch;

import com.geek.gkbgw.framework.dispatch.annotation.Dispatch;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.stereotype.Component;

/**
 * 请输入一句美丽的描述话语
 *
 * @author hmilyylimh
 * ^_^
 * @version 0.0.1
 * ^_^
 * @date 2022-03-19
 */
public class DispatchDemo {

    public static void main(String[] args) {
        // 注意，这里只是给出样例怎么调用而已
        String key = "cat";

        // 通过 DispatchFinder 分派 Animal 接口对应的实现类
        Animal animal = DispatchFinder.find(key, Animal.class);
        // 然后进行方法调用
        animal.eat();
    }

    interface Animal {
        void eat();
    }

    @Component
    @Dispatch(value = "cat", group = AnimalEnums.class)
    static class Cat implements Animal {
        @Override
        public void eat() {
            System.out.println("猫吃鱼");
        }
    }

    @Component
    @Dispatch(value = "dog", group = AnimalEnums.class)
    static class Dog implements Animal {
        @Override
        public void eat() {
            System.out.println("狗啃骨头");
        }
    }

    @Getter
    @AllArgsConstructor
    public enum AnimalEnums {
        /** <h2>"cat","猫"</h2> **/
        CAT("cat","猫"),

        /** <h2>"dog","狗"</h2> **/
        DOG("dog","狗"),
        ;

        private final String code;
        private final String desc;
    }
}